<?php
defined('_JEXEC') or die('Restricted access');

/**
 * Description of deepDynamicContainer
 *
 * @author George Zeakis<zeageorge@google.com>
 */
class deepDynamicContainer {
    protected $_container = array();

    public function __construct(array $deepContainer=array()) { 
        if (count($deepContainer)>0){
            foreach ($deepContainer as $key => $value) {
                if (is_array($key)){
                    $this->_container[$key]=new $this(array($key=>$value));
                } else {
                    $this->_container[$key]=$value;
                }
            }
        }
    }

    public function __get($name){
        if (isset($this->_container[$name])){
            if($this->_container[$name] instanceof $this){
                return $this->_container[$name]->{$name};
            } else {
                return $this->_container[$name];
            }    
        } else { 
            $this->_container[$name] = new $this(array($name=>''));
            return $this->_container[$name]; 
        }
    }
    
    public function __set($name,$value){ 
        if (isset($this->_container[$name])){
            $alal = $this->_container;
            $alal[$name] = new $this(array($name,$value)); 
            $this->_container = $alal;
        } else {
            $lala = $this->_container;
            $lala[$name] = new $this(array($name,$value));
            $this->_container = $lala;
        }    
    }
    
    public function __isset($name){ return isset($this->_container[$name]); }
    public function __unset($name){ unset($this->_container[$name]);        }
    
    public function toArray(){ return (array)$this->_container; }
    
    public function __destruct() { }
}

?>
